//
//  SYChangePasswordViewController.m
//  BSHOUYIFANG
//
//  Created by 曹雁彬 on 15/8/21.
//  Copyright (c) 2015年 CYB. All rights reserved.
//

#import "SYChangePasswordViewController.h"
#import "Header.h"
#import "SYUser.h"
#import "SYFileHandle.h"
#import "SYMyFmdb.h"
@interface SYChangePasswordViewController ()
@property(nonatomic,strong)UILabel *phoneNumber;
@property(nonatomic,strong)UITextField *userName;
@property(nonatomic,strong)UITextField *password;
@property(nonatomic,strong)UITextField *confirmPassword;
@property (nonatomic,strong)UIButton *nextButton;

@end

@implementation SYChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    self.navigationController.navigationBar.translucent = NO;
    _phoneNumber = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_HEIGHT/16, 20, SCREEN_WIDTH/1.3, SCREEN_WIDTH/10)];
    _phoneNumber.text = _str;
    _phoneNumber.textAlignment = NSTextAlignmentCenter;
    _phoneNumber.font = [UIFont systemFontOfSize:20];
     [self.view addSubview:_phoneNumber];

    _userName = [[UITextField alloc] initWithFrame:CGRectMake(SCREEN_HEIGHT/16, SCREEN_WIDTH/10+20+15, SCREEN_WIDTH/1.3, SCREEN_WIDTH/10)];
    _userName.borderStyle = UITextBorderStyleRoundedRect;
    _userName.placeholder =@"昵 称";
    [self.view addSubview:_userName];
    //SFA 
    _password = [[UITextField alloc] initWithFrame:CGRectMake(SCREEN_HEIGHT/16, (SCREEN_WIDTH/10)*2+20+30, SCREEN_WIDTH/1.3, SCREEN_WIDTH/10)];
    _password.borderStyle = UITextBorderStyleRoundedRect;
    _password.placeholder =@"请再次输入密码";
    [self.view addSubview:_password];
    
    
    _confirmPassword = [[UITextField alloc] initWithFrame:CGRectMake(SCREEN_HEIGHT/16, (SCREEN_WIDTH/10)*3+20+45, SCREEN_WIDTH/1.3, SCREEN_WIDTH/10)];
    _confirmPassword.borderStyle = UITextBorderStyleRoundedRect;
    _confirmPassword.placeholder =@"请再次输入密码";
    [self.view addSubview:_confirmPassword];

    
    _nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _nextButton.frame = CGRectMake(SCREEN_WIDTH/12,(SCREEN_WIDTH/10)*4+20+60,SCREEN_WIDTH/1.2,SCREEN_WIDTH/10);
    _nextButton.backgroundColor = [UIColor redColor];
    [_nextButton addTarget:self action:@selector(nextButton:) forControlEvents:UIControlEventTouchUpInside];
    [_nextButton setTitle:@"注册并登陆" forState:UIControlStateNormal];
    _nextButton.titleLabel.textColor =[UIColor whiteColor];
    [self.view addSubview:_nextButton];
    // Do any additional setup after loading the view.
}
- (void)nextButton:(UIButton *)sender
{
    SYUser *user = [[SYUser alloc]init];
    user.password = _password.text;
    user.phoneNumber = [_phoneNumber.text substringFromIndex:4];
    user.username = _userName.text;
    user.isLogin = YES;
    UIImage *image = [UIImage imageNamed:@"circle_default_face"];
    user.icon = UIImagePNGRepresentation(image);
    [[SYMyFmdb shareInstance]addWithUser:user];
    [[SYFileHandle shareInstance] setloginState:YES];
    [[SYFileHandle shareInstance] setUserForAll:user];
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
